<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
$('#tt').tabs({
    border:false,
    onSelect:function(title){
		alert(title+' is selected');
    }
});
$(".dsxz_xingzeng").click(function(){

    $("#dsxz_timu").val("");
	$("#dsxz_xxa").val("");
	$("#dsxz_xxb").val("");
	$("#dsxz_xxc").val("");
	$("#dsxz_xxd").val("");
	$("#dsxz_daan").val("");
	 var tk=$("#Tiku").combobox("getValue");
	 var zsz=$("#Zhishizu").combobox("getValue");
	 var nyd=$("#Nanyidu").combobox("getValue");
	 var fs=$("#Fenshu").combobox("getText");
	if(tk==""){
      $("#tkxz_panduan2").show();
	  $("#tkxz_panduan2").text("题库不能为空（勾选/输入）!").fadeOut(3000);
   }else if(zsz==""){
   	$("#tkxz_panduan2").show();
   	$("#tkxz_panduan2").text("知识组不能为空（勾选/输入）!").fadeOut(3000);
   }else if(nyd==""){
   	$("#tkxz_panduan2").show();
   	$("#tkxz_panduan2").text("难易度不能为空（勾选/输入）!").fadeOut(3000);
   }else if(fs==""){
   	$("#tkxz_panduan2").show();
   	$("#tkxz_panduan2").text("分数不能为空（勾选/输入）!").fadeOut(3000);
   }else{
		$("#tk_danshunxingzeng").window("open"); 
   } 
	
});

//点击保存按钮关闭窗口
$(".zhxz_shitibaocun").click(function(){
	 $("#tk_danshunxingzeng").window("close"); 
})

$(function(){
 	$('#dsxz_anpai').datagrid({    
 		//数据源地址
	    columns:[[
	    	{field:'TIMU',fixed:false,width:180,title:'题目',align:'center'},    
	        {field:'XUNXIANGA',fixed:false,width:180,title:'选项A',align:'center'},    
	        {field:'XUNXIANGB',fixed:false,width:180,title:'选项B',align:'center'},
	        {field:'XUNXIANGC',fixed:false,width:180,title:'选项C',align:'center'},
	        {field:'XUNXIANGD',fixed:false,width:180,title:'选项D',align:'center'},
	        {field:'DAAN',fixed:false,width:180,title:'答案',align:'center'},
	        {field:'caozuo',width:260,formatter:operate,title:'操作',align:'center'} 
	    
	    ]],
	    pagination:true,
	    pageNumber:1,
	    pageSize:5,
	    pageList:[5,10,15]         
	});
 	//在每个操作列里面添加编辑，查看，明细，删除
 	function operate(value, row, index) { 	
 	     return "<button class='dsxz_shanchu' onClick='tkds_shanchu("+index+")'>删除</button>";
 	} 
})

function tkds_shanchu(indexs){
	$("#dsxz_anpai").datagrid("deleteRow",indexs); 	
}
function AnswerVer(das){
	var da=das.split("");
	if(da.length>3)
		return false;
	for (var i = 0; i < da.length; i++) {
		for (var j = 0; j < da.length; j++) {
			if(i==j)
				break;
			if(da[i]==da[j])
				return false;
		}
	}
	for (var i = 0; i < da.length; i++) {
		if(da[i]!= "A" && da[i]!= "B" && da[i]!= "C" && da[i]!= "D")
			return false;
	}
	return true;
}
 
function JSONSorting(das){
	var da=das.split("");
	s = da.sort().toString().replace(/,/gi,"");
	var obj=Array.prototype.slice.call(s,0);
	var obj = s.replace(/(.)(?=[^$])/g,"$1").split(",");
	return obj+"";
}

$(function(){
	//提示框隐藏
	$("#tkxz_panduan").hide();
	$("#tkxz_panduan2").hide();
	//显示
	 $('#Tiku').combobox({
		 url:'tiku',
		 valueField:'QSBID',
		 textField:'QSBBANK'
	 });
	
	 $('#Zhishizu').combobox({
		 url:'zhishidian',
		 valueField:'TMZID',
		 textField:'tmzsd'
	 });
	 
	 $('#Nanyidu').combobox({
		 url:'nanyidu',
		 valueField:'TMZID',
		 textField:'tmnyd'
	 });
	 
	 $('#Fenshu').combobox({
		 url:'fenshu',
		 valueField:'TMZID',
		 textField:'TMFS'
	 });
	
	
	  $(".dsxz_shitibaocun").click(function(){
		 var tm=$("#dsxz_timu").val();
		 var a=$("#dsxz_xxa").val();
		 var b=$("#dsxz_xxb").val();
		 var c=$("#dsxz_xxc").val();
		 var d=$("#dsxz_xxd").val();
		 var da=$("#dsxz_daan").val();
		 var ss = AnswerVer(da);
		    if(tm==""){
		    	$("#tkxz_panduan").show();
		    	$("#tkxz_panduan").text("题目不能为空!").fadeOut(3000);
		    }else if(a==""){
		    	$("#tkxz_panduan").show();
		    	$("#tkxz_panduan").text("选项A不能为空!").fadeOut(3000);
		    }else if(b==""){
		    	$("#tkxz_panduan").show();
		    	$("#tkxz_panduan").text("选项B不能为空!").fadeOut(3000);
		    }else if(c==""){
		    	$("#tkxz_panduan").show();
		    	$("#tkxz_panduan").text("选项C不能为空!").fadeOut(3000);
		    }else if(d==""){
		    	$("#tkxz_panduan").show();
		    	$("#tkxz_panduan").text("选项D不能为空!").fadeOut(3000);
		    }else if(da==""){
		    	$("#tkxz_panduan").show();
		    	$("#tkxz_panduan").text("答案不能为空!").fadeOut(3000);
		    }else if(!ss){  
		    	$("#tkxz_panduan").show();
		    	$("#tkxz_panduan").text("答案格式提示 单选:(A)多选：(AB)(ABC)!").fadeOut(5000);
			 }else{
		    	 
				 var row = {
						 TIMU:$("#dsxz_timu").val(),
						 XUNXIANGA:a,
						 XUNXIANGB:b,
						 XUNXIANGC:c,
						 XUNXIANGD:d,
						 DAAN:JSONSorting(da),
				};
						 $('#dsxz_anpai').propertygrid('appendRow',row);
						 $("#tk_danshunxingzeng").window("close"); 
		    }
	  });
	 
	 $(".dsxz_bao").click(function(){
		 var tk=$("#Tiku").combobox("getText");
		 var zsz=$("#Zhishizu").combobox("getText");
		 var nyd=$("#Nanyidu").combobox("getText");
		 var fs=$("#Fenshu").combobox("getText");
		 
		 var rows = $("#dsxz_anpai").datagrid("getRows");
		 for(var i=0;i<rows.length;i++){
			 $.ajax({
				 url:"shunzheti",
				 type:"post",
				 data:{
					 tmid:null,
					 tk:tk,
					 zsz:zsz,
					 nyd:nyd,
					 fs:fs,
					 type:"选择题",
					 TIMU:rows[i]["TIMU"]+"#"+rows[i]["XUNXIANGA"]+"#"+rows[i]["XUNXIANGB"]+"#"+rows[i]["XUNXIANGC"]+"#"+rows[i]["XUNXIANGD"],
					 DAAN:rows[i]["DAAN"]
				 },
			     success:function(){
			    	
			    	
			     }
			 
			 }) 
		 }
		    $("#dsxz_timu").val("");
			$("#dsxz_xxa").val("");
			$("#dsxz_xxb").val("");
			$("#dsxz_xxc").val("");
			$("#dsxz_xxd").val("");
			$("#dsxz_daan").val("");
		 
		   $("#tk_danshuntankuang").window("open"); 
		   
	 });
	
});



$("#dsx-beok").click(function(){
	add("tk-dan-shun");
})
//点击保存按钮关闭窗口
/* $(".dsxz_shitibaocun").click(function(){
	 $("#tk_danshunxingzeng").window("close"); 
}) */


$(".dsxz_queding").click(function(){
	$("#tk_danshuntankuang").window("close"); 
	close("新增选择试题");
});

$(".dsxz_qu").click(function(){
	$("#tkds_quxiao").window("open"); 
});

$(".dsxz_queding").click(function(){
	$("#tkds_quxiao").window("close"); 
	close("新增选择试题");
});
</script>
                 <div class="tkxz_panduan2" id="tkxz_panduan2" ></div>
			      <div id="tk_danshunxingzeng" class="easyui-window" title="考题详情" style="width:690px;height:350px"
		    		data-options="closed:true,minimizable:false,maximizable:false,collapsible:false,modal:true">
		    		             <div class="danshunxingzeng_one">
		    		                   <div class="dsxz_xunxiang">题目：<input type="text" class="dsxz_tiqukuang" id="dsxz_timu"></div>
		    		                   <div class="dsxz_xunxianga">选项A:<input type="text" class="dsxz_tiqukuang" id="dsxz_xxa"></div>
		    		             </div>
		    		             <div class="danshunxingzeng_two">
		    		                   <div class="dsxz_xunxiangb">选项B:<input type="text" class="dsxz_tiqukuang" id="dsxz_xxb"></div>
		    		                   <div class="dsxz_xunxiangc">选项C:<input type="text" class="dsxz_tiqukuang" id="dsxz_xxc"></div>
		    		             </div>
		    		             <div class="danshunxingzeng_three">
		    		                   <div class="dsxz_xunxiangd">选项D:<input type="text" class="dsxz_tiqukuang" id="dsxz_xxd"></div>
		    		                   <div class="dsxz_daan">答案：<input type="text" class="dsxz_tiqukuang" id="dsxz_daan"></div>
		    		             </div>
		    		             <div class="danshunxingzeng_four">
		    		                  <button class="dsxz_shitibaocun"><img src="../static/tyl/images/go.png">保存</button>
		    		             </div>
		    		             
		    		             <div class="tkxz_panduan" id="tkxz_panduan" >
		    		             </div>
                 </div>
		    		
		    		  <div id="tk_danshuntankuang" class="easyui-window" title="新增" style="width:320px;height:165px"
		    		     data-options="closed:true,minimizable:false,maximizable:false,collapsible:false,modal:true">
		    		             <div class="danshuntankuang_one">
		    		                   <div class="dsxz_chenggong">新增成功！</div>
		    		                  
		    		             </div>
		    		             <div class="danshuntankuang_two">
		    		                  <button id="dsx-beok" class="dsxz_queding">确定</button>
		    		             </div>
		    		   </div>
		    		    <div id="tkds_quxiao" class="easyui-window" title="新增" style="width:320px;height:165px"
		    		     data-options="closed:true,minimizable:false,maximizable:false,collapsible:false,modal:true">
		    		             <div class="danshuntankuang_one">
		    		                   <div class="dsxz_chenggong">确定取消新增选择题？</div>
		    		                  
		    		             </div>
		    		             <div class="danshuntankuang_two">
		    		                  <button id="dsx-beok" class="dsxz_queding">确定</button>
		    		             </div>
		    		    </div>
       <div class="danshunxingzeng_zong">
             <div class="danshunxingzeng_top">
                  <div class="dsxz_one">
                        <div class="dsxz_tiku">
                             <div class="dsxz_tikuone">
                                <img src="../static/tyl/images/tiku.png">
                             </div>
                              <div class="dsxz_tikutwo">题库：
                              	<input id="Tiku" class="easyui-combobox tikeshuru">
		    		          </div>
		    		     </div>
		    		
                       <div class="dsxz_zhishizu">
                             <div class="dsxz_zhishizuone">
                                <img src="../static/tyl/images/zhishi.png">
                             </div>
                             <div class="dsxz_zhishizutwo">知识组
                             <input id="Zhishizu" class="easyui-combobox zhishizushuru">
		    		          </div>
		    		    </div>
		    		</div>
                  <div class="dsxz_two">
                       <div class="dsxz_nanyidu">
                              <div class="dsxz_nanyiduone">
                                <img src="../static/tyl/images/nanyidu.png">
                             </div>
                             <div class="dsxz_nanyidutwo">难易度
                             <input id="Nanyidu" class="easyui-combobox nanyidushuru">
                    
		    		          </div>
		    		     </div>
                        <div class="dsxz_fenzhi">
                             <div class="dsxz_fenzhione">
                                <img src="../static/tyl/images/fenzhi.png">
                             </div>
                             <div class="dsxz_fenzhitwo">分值：
                             <input id="Fenshu" class="easyui-combobox fenshushuru">
                             
		    		          </div>
		    		     </div>
                   </div>
                  <div class="dsxz_three">
		    		     <div class="dsxz_shunxiangshu">
                             <div class="dsxz_shunxiangshuone">
                                <img src="../static/tyl/images/shunxiang.png">
                             </div>
                              <div class="dsxz_shunxiangshutwo">题目：
                                  <button class="dsxz_xingzeng">新增</button>
		    		          </div>
		    		    </div>
		    	</div>
		  </div>
		 
		  
             <div class="danshunxingzeng_bottom">
                      <table id="dsxz_anpai" class="easyui-datagrid" style="width:100%;height:280px;margin-top:20px;" data-options="fitColumns:true">
                                   
                      </table>
                           <div class="dsxz_anniu">
                           
                             <div class="dsxz_baocun">   <button id="dsxz-save" class="dsxz_bao"><img src="../static/tyl/images/go.png">保存</button> </div>
                             <div class="dsxz_quxiao">   <button id="dsxz-save" class="dsxz_qu"><img src="../static/tyl/images/cha.png">取消</button> </div>
                           
                           </div>
             </div> 
       </div>    
</body>
</html>